package com.darren.euc.job;

import java.sql.SQLException;

import javax.naming.NamingException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import com.darren.euc.service.BillService;



@Component
public class BillTask {	

	private static final Logger log = Logger.getLogger(BillTask.class);
	
	@Autowired
    private BillService billService;
	
	
	
	/**
	 * 定时生成帐单数据
	 * @throws SQLException
	 * @throws NamingException
	 */
	@Scheduled(cron = "0 0/5 * * * ?")
	public void refreshSystemParameter() throws SQLException, NamingException {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		log.info("generate bill data job launch start ..." + System.currentTimeMillis());		
		try {
			billService.generateBillData();
		} catch (Exception e) {
		    log.error(e.getMessage(),e);
		}	
		log.info("generate bill data job launch end   ..." + System.currentTimeMillis());
		stopWatch.stop();
		log.info("generate bill data job launch total time ..."+ stopWatch.getTotalTimeMillis());
	}
	
	
	/**
	 * 定时刷新帐单状态
	 * @throws SQLException
	 * @throws NamingException
	 */
	@Scheduled(cron = "0 0/30 * * * ?")
	public void refreshScreenToken() throws SQLException, NamingException {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		log.info("update bill status  job launch start ..." + System.currentTimeMillis());		
		try {
			billService.updateBillStatus();
		} catch (Exception e) {
		    log.error(e.getMessage(),e);
		}	
		log.info("update bill status  job launch end   ..." + System.currentTimeMillis());
		stopWatch.stop();
		log.info("update bill status  job launch total time ..."+ stopWatch.getTotalTimeMillis());
	}
	
}
